//创造敌机的构造函数
function enemies(){
	this.el     = null; 
	this.iTimer = null; //定时器
	this.iBlood = null; //血量
	this.iSpeed = null; //速度
}
//飞机类型
enemies.prototype.big    = '3';
enemies.prototype.middle = '2';
enemies.prototype.small  = '1';

//创造敌机
enemies.prototype.create = function(type){
	var 
		oBox   = $('box'),
		oEnemy = createHtml('div');
	switch(type){
		case enemies.prototype.big:
			oEnemy.className = 'big';
			this.iBlood = 5;
			this.iSpeed = 5;
			this.die    = ['plane3_die1.png','plane3_die2.png','plane3_die3.png','plane3_die4.png','plane3_die5.png','plane3_die5.png','plane3_die6.png'];;
			break;
		case enemies.prototype.middle:
			oEnemy.className = 'middle';
			this.iBlood = 3;
			this.iSpeed = 8;
			this.die    = ['plane2_die1.png','plane2_die2.png','plane2_die3.png','plane2_die4.png'];
			break;
		case enemies.prototype.small:
			oEnemy.className = 'small';
			this.iBlood = 1;
			this.iSpeed = 10;
			this.die    = ['plane1_die1.png','plane1_die2.png','plane1_die3.png']
			break;	
	};
	document.body.appendChild(oEnemy);

	//随机生成位置
	oEnemy.style.top  = -oEnemy.offsetHeight + 'px';
	oEnemy.style.left = (oBox.offsetWidth - oEnemy.offsetWidth ) * Math.random() + oBox.offsetLeft + 'px';
	this.el = oEnemy;

	// 将敌机存储到Engine中
	var iKey = new Date().getTime();
	play.oEnemies[iKey] = this;
	this.key = iKey;

	return this;

}
//敌机运动
enemies.prototype.move = function(){
	let iWinH = document.documentElement.clientHeight;
	this.iTimer = setInterval(function(){
		this.el.style.top = this.el.offsetTop + this.iSpeed + 'px';
		if(this.el.offsetTop >= iWinH){
			this.destroy();
		}
	}.bind(this),50);	
}
//敌机销毁
enemies.prototype.destroy = function(){
	// 将子弹从数组中移除
	delete play.oEnemies[this.key];
	//清除定时器
	clearInterval(this.iTimer);
	//死亡动画
	var
		iIndex = 0,
	iTimer = setInterval(function () {
	this.el.style.backgroundImage = 'url(img/'+this.die[iIndex]+')';

	iIndex++;

	if(iIndex >= this.die.length) {
		clearInterval(iTimer);
		// 移除DOM节点
		document.body.removeChild(this.el);
	}
	}.bind(this), 100);
}